//
// Copyright (C) 2024 Kumo group inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <turbo/flags/flag.h>
#include <turbo/flags/declare.h>
#include <krpc/var/config.h>
#include <krpc/utility/config.h>
#include <krpc/kthread/config.h>

TURBO_DECLARE_FLAG(bool, usercode_in_pthread);


TURBO_DECLARE_FLAG(int32_t, event_dispatcher_num);

TURBO_DECLARE_FLAG(bool, usercode_in_coroutine);

TURBO_DECLARE_FLAG(int64_t, socket_max_streams_unconsumed_bytes);

TURBO_DECLARE_FLAG(std::string, rpc_profiling_dir);

TURBO_DECLARE_FLAG(bool, enable_rpcz);

TURBO_DECLARE_FLAG(int32_t, health_check_timeout_ms);

TURBO_DECLARE_FLAG(bool, log_connected);

TURBO_DECLARE_FLAG(bool, log_idle_connection_close);

TURBO_DECLARE_FLAG(int32_t, socket_recv_buffer_size);

// Default value of SNDBUF is 2500000 on most machines.
TURBO_DECLARE_FLAG(int32_t, socket_send_buffer_size);

TURBO_DECLARE_FLAG(int32_t, ssl_bio_buffer_size);

TURBO_DECLARE_FLAG(int64_t, socket_max_unwritten_bytes);

TURBO_DECLARE_FLAG(int64_t, socket_max_streams_unconsumed_bytes);

TURBO_DECLARE_FLAG(int32_t, max_connection_pool_size);

TURBO_DECLARE_FLAG(int32_t, connect_timeout_as_unreachable);


TURBO_DECLARE_FLAG(int32_t, health_check_interval);
TURBO_DECLARE_FLAG(int32_t, idle_timeout_second);
TURBO_DECLARE_FLAG(int32_t, defer_close_second);
TURBO_DECLARE_FLAG(bool, show_socketmap_in_vars);
TURBO_DECLARE_FLAG(bool, reserve_one_idle_socket);

TURBO_DECLARE_FLAG(std::string, health_check_path);
TURBO_DECLARE_FLAG(int32_t, health_check_timeout_ms);

TURBO_DECLARE_FLAG(bool, allow_chunked_length);
TURBO_DECLARE_FLAG(bool, allow_http_1_1_request_without_host);
TURBO_DECLARE_FLAG(bool, http_verbose);
TURBO_DECLARE_FLAG(int32_t, http_verbose_max_body_length);

TURBO_DECLARE_FLAG(int32_t, channel_check_interval);

#if KRPC_WITH_RDMA
TURBO_DECLARE_FLAG(int32_t, rdma_max_sge);
TURBO_DECLARE_FLAG(std::string, rdma_device;
TURBO_DECLARE_FLAG(int32_t, rdma_port);
TURBO_DECLARE_FLAG(int32_t, rdma_gid_index);

TURBO_DECLARE_FLAG(int32_t, rdma_sq_size);
TURBO_DECLARE_FLAG(int32_t, rdma_rq_size);
TURBO_DECLARE_FLAG(bool, rdma_recv_zerocopy);
TURBO_DECLARE_FLAG(int32_t, rdma_zerocopy_min_size);
TURBO_DECLARE_FLAG(std::string, rdma_recv_block_type);
TURBO_DECLARE_FLAG(int32_t, rdma_cqe_poll_once);
TURBO_DECLARE_FLAG(int32_t, rdma_prepared_qp_size);
TURBO_DECLARE_FLAG(int32_t, rdma_prepared_qp_cnt);
TURBO_DECLARE_FLAG(bool, rdma_trace_verbose);
#endif // KRPC_WITH_RDMA

TURBO_DECLARE_FLAG(bool, rpc_dump);
TURBO_DECLARE_FLAG(std::string, rpc_dump_dir);
TURBO_DECLARE_FLAG(int32_t, rpc_dump_max_files);
TURBO_DECLARE_FLAG(int32_t, rpc_dump_max_requests_in_one_file);

TURBO_DECLARE_FLAG(uint64_t, max_body_size);

TURBO_DECLARE_FLAG(bool, log_error_text);

TURBO_DECLARE_FLAG(int32_t, timeout_cl_sample_window_size_ms);
TURBO_DECLARE_FLAG(int32_t, timeout_cl_min_sample_count);
TURBO_DECLARE_FLAG(int32_t, timeout_cl_max_sample_count);
TURBO_DECLARE_FLAG(double, timeout_cl_sampling_interval_ms);
TURBO_DECLARE_FLAG(int32_t, timeout_cl_initial_avg_latency_us);
TURBO_DECLARE_FLAG(bool, timeout_cl_enable_error_punish);
TURBO_DECLARE_FLAG(double, timeout_cl_fail_punish_ratio);
TURBO_DECLARE_FLAG(int32_t, timeout_cl_default_timeout_ms);
TURBO_DECLARE_FLAG(int32_t, timeout_cl_max_concurrency);

TURBO_DECLARE_FLAG(bool, log_connection_close);


TURBO_DECLARE_FLAG(bool, socket_keepalive);

TURBO_DECLARE_FLAG(int32_t, socket_keepalive_idle_s);

TURBO_DECLARE_FLAG(int32_t, socket_keepalive_interval_s);

TURBO_DECLARE_FLAG(int32_t, socket_keepalive_count);

TURBO_DECLARE_FLAG(bool, redis_verbose);
TURBO_DECLARE_FLAG(bool, redis_verbose_crlf2space);


TURBO_DECLARE_FLAG(bool, show_lb_in_vars);
TURBO_DECLARE_FLAG(int32_t, default_weight_of_wlb);
TURBO_DECLARE_FLAG(int32_t, free_memory_to_system_interval);
TURBO_DECLARE_FLAG(bool, show_hostname_instead_of_ip);

TURBO_DECLARE_FLAG(int32_t, max_shown_connections);

TURBO_DECLARE_FLAG(bool, enable_dir_service);
TURBO_DECLARE_FLAG(bool, enable_threads_service);

TURBO_DECLARE_FLAG(int32_t, usercode_backup_threads);
TURBO_DECLARE_FLAG(int32_t, max_pending_in_each_backup_thread);

TURBO_DECLARE_FLAG(bool, enable_rpcz);

TURBO_DECLARE_FLAG(bool, rpcz_hex_log_id);

TURBO_DECLARE_FLAG(int32_t, circuit_breaker_short_window_size);
TURBO_DECLARE_FLAG(int32_t, circuit_breaker_long_window_size);
TURBO_DECLARE_FLAG(int32_t, circuit_breaker_short_window_error_percent);
TURBO_DECLARE_FLAG(int32_t, circuit_breaker_long_window_error_percent);
TURBO_DECLARE_FLAG(int32_t, circuit_breaker_min_error_cost_us);
TURBO_DECLARE_FLAG(int32_t, circuit_breaker_max_failed_latency_mutiple);
TURBO_DECLARE_FLAG(int32_t, circuit_breaker_min_isolation_duration_ms);
TURBO_DECLARE_FLAG(int32_t, circuit_breaker_max_isolation_duration_ms);
TURBO_DECLARE_FLAG(double, circuit_breaker_epsilon_value);
TURBO_DECLARE_FLAG(int32_t, circuit_breaker_half_open_window_size);


TURBO_DECLARE_FLAG(int32_t, auto_cl_sample_window_size_ms);
TURBO_DECLARE_FLAG(int32_t, auto_cl_min_sample_count);
TURBO_DECLARE_FLAG(int32_t, auto_cl_max_sample_count);
TURBO_DECLARE_FLAG(double, auto_cl_sampling_interval_ms);
TURBO_DECLARE_FLAG(int32_t, auto_cl_initial_max_concurrency);
TURBO_DECLARE_FLAG(int32_t, auto_cl_noload_latency_remeasure_interval_ms);
TURBO_DECLARE_FLAG(double, auto_cl_alpha_factor_for_ema);
TURBO_DECLARE_FLAG(bool, auto_cl_enable_error_punish);
TURBO_DECLARE_FLAG(double, auto_cl_fail_punish_ratio);
TURBO_DECLARE_FLAG(double, auto_cl_max_explore_ratio);
TURBO_DECLARE_FLAG(double, auto_cl_min_explore_ratio);
TURBO_DECLARE_FLAG(double, auto_cl_change_rate_of_explore_ratio);
TURBO_DECLARE_FLAG(double, auto_cl_reduce_ratio_while_remeasure);
TURBO_DECLARE_FLAG(int32_t, auto_cl_latency_fluctuation_correction_factor);

TURBO_DECLARE_FLAG(int64_t, detect_available_server_interval_ms);

TURBO_DECLARE_FLAG(int32_t, ns_access_interval);

TURBO_DECLARE_FLAG(int32_t, chash_num_replicas);

TURBO_DECLARE_FLAG(int32_t, max_tc_stats_buf_len);

TURBO_DECLARE_FLAG(int32_t, max_profiling_seconds);
TURBO_DECLARE_FLAG(int32_t, max_profiles_kept);

TURBO_DECLARE_FLAG(int32_t, max_flame_graph_width);

TURBO_DECLARE_FLAG(int32_t, h2_client_header_table_size);
TURBO_DECLARE_FLAG(int32_t, h2_client_stream_window_size);
TURBO_DECLARE_FLAG(int32_t, h2_client_connection_window_size);
TURBO_DECLARE_FLAG(int32_t, h2_client_max_frame_size);

TURBO_DECLARE_FLAG(bool, h2_hpack_encode_name);
TURBO_DECLARE_FLAG(bool, h2_hpack_encode_value);

TURBO_DECLARE_FLAG(int64_t, min_weight);
TURBO_DECLARE_FLAG(double, punish_inflight_ratio);
TURBO_DECLARE_FLAG(double,punish_error_ratio);
